package gamble.notice.command;
import gamble.notice.dao.BoardDaoImp;
import gamble.notice.vo.BoardVO;

import java.io.File;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;


@Controller
public class FileDownLoadController  
         
{
 
 private String realUploadPath;
 private BoardDaoImp dao;
  
 
public void setRealUploadPath(String realUploadPath) {
	this.realUploadPath = realUploadPath;
}


public void setDao(BoardDaoImp dao) {
	this.dao = dao;
}
 
@RequestMapping("/fileDown.htm")
public ModelAndView handleRequest(HttpServletRequest request) {
   //File downloadFile =getFile(request);
   int num=Integer.parseInt(request.getParameter("num"));
   BoardVO vo=dao.getView(num);
   File downloadFile=new File(vo.getUpload2());
   /*
    ModelAndView mv=new ModelAndView();
    mv.setViewName("download");
    mv.addObject("downloadFile", downloadFile);
    */
             //            ("뷰",           "모델명",       모델값)
  return new ModelAndView("download","downloadFile",downloadFile);
 }
 /*
 private File getFile(HttpServletRequest request){
	 String path="";
  String fileName = (String)request.getParameter("files");
 
  //String path = context.getServletContext().getRealPath(realUploadPath+fileName);
  //System.out.println(context.getServletContext().getRealPath("/file/"));
try{
   path =realUploadPath+URLDecoder.decode(fileName,"utf-8");
}catch(Exception e){}
  return new File(path);
 }
 */

/* public void setApplicationContext(ApplicationContext applicationContext)
     throws BeansException {
  this.context = (WebApplicationContext)applicationContext;
 }*/
}




